home *** CD-ROM | disk | FTP | other *** search
- Path: news.spies.com!usenet
- From: Erik Max Francis <max@alcyone.com>
- Newsgroups: comp.lang.c
- Subject: Re: Is This Bad Coding Practice?
- Date: Sat, 30 Mar 1996 00:57:46 -0800
- Organization: Alcyone Systems
- Message-ID: <315CF78A.4F23D93C@alcyone.com>
- References: <4jgnt2$9d1@loki.tor.hookup.net>
- NNTP-Posting-Host: newton.alcyone.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i486)
-
- Rajendra Singh wrote:
-
- > ... since I am using the value returned from func1() immediately (in
- > main()), is this reliable? After I copy it into "string", I won't be
- > using that area of memory anymore (i. e. the pointer returned by
- > func1()).
-
- No, it is not reliable. Once control leaves a block, the local variables in
- that block go out of scope. Your string in the function goes out of scope when
- you return from the function, and so you can't assume that pointers to that
- local variable will still point to valid data outside of its scope.
-
- This is one of the worst kinds of bugs; oftentimes, in most compilers, the
- operation will _almost_ always work. Occasionally, though, it will fail.
-
- --
- Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max@alcyone.com
- San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
- H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
- Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
- "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
-